//
//  JZGetBackPasswordViewController.m
//  QuanZiChat
//
//  Created by 张洪林 on 15/11/17.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "JZGetBackPasswordViewController.h"
#import "JZLoginViewController.h"
@interface JZGetBackPasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *email;

@end

@implementation JZGetBackPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.email resignFirstResponder];
}

- (IBAction)sendMail:(id)sender {
    
    [AVUser requestPasswordResetForEmailInBackground:self.email.text block:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            
            NSLog(@"邮件发送成功");
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"恭喜" message:@"邮件发送成功，请登录你的邮箱查收" preferredStyle:(UIAlertControllerStyleAlert)];
            
            UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"返回登录界面" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
               
                //JZLoginViewController *loginVC = [self.storyboard instantiateViewControllerWithIdentifier:@"JZLoginViewController"];
                
                [self dismissViewControllerAnimated:YES completion:nil];
                
            }];
            
            [alertController addAction:alertAction];
            
            [self presentViewController:alertController animated:YES completion:nil];
            
            
        } else {
            
            NSLog(@"邮件发送失败");
        }
    }];
}
//返回登录界面
- (IBAction)returenToLoginVC:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
